<template>
  <div>
    <div class="wrap">
      <div style="flex:1;  padding-top: 20px;">
        <img style="width: 85px;" src="../../assets/images/commonPropertypage/showSuccess.png">
      </div>
      <div style="flex:3;    padding-top: 20px;">
        <div style="margin-bottom: 10px;color: gray;font-size: 15px;">您的请求已提交,系统返回如下信息:</div>
        <div
          style="margin-bottom: 10px;
            font-size: 20px;
            color: #679cf6;
            font-weight: bolder;"
        >您的操作已成功</div>
        <div style="margin-bottom: 10px;color: gray;font-size: 15px;">{{ time }}秒后页面自动返回首页</div>
        <div
          style="text-align: right;
                padding-right: 20px;margin-top: 10px;"
        >
          <el-button type="small" @click="closePage">关闭</el-button>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
import { getToken } from '@/utils/auth.js';
export default {
  name: 'ShowSuccessTree',
  data() {
    return {
      time: 3,
      alreadydo: 0,
      restdo: 0,
      sId: '',
      isFlag: '0',
      timer: ''
    };
  },
  created() {
    this.sId = this.$route.query.sId;
    this.isFlag = this.$route.query.flag;
  },
  beforeDestroy() {
    clearInterval(this.timer);
  },
  methods: {

    closePage() {
      if (this.isFlag === 0) {
        window.top.postMessage('close');
      } else {
        this.gotoPath({});
      }
    },
    treego() {
      this.timer = setInterval(() => {
        this.time--;
        if (this.time === 0) {
          // clearInterval(this.timer);
          // window.close();
          // this.gotoPath({});
        }
      }, 1000);
    },
    gotoPath(view) {
      localStorage.setItem('isShowTips', 'false');
      this.$store.dispatch('tagsView/delAllViews').then(({ visitedViews }) => {
        this.toLastView(visitedViews, view);
      });
    },
    toLastView(visitedViews, view) {
      const latestView = visitedViews.slice(-1)[0];
      if (latestView) {
        this.$router.push(latestView);
      } else {
        // now the default is to redirect to the home page if there is no tags-view,
        // you can adjust it according to your needs.
        if (view.name === 'Dashboard') {
          // to reload home page
          this.$router.replace({ path: '/redirect' + view.fullPath });
        } else {
          // this.$router.push('/propertyHomePage');
          const pcUrlName = getToken('pcUrlName');
          if (pcUrlName === '/special/home' && window.history.length > 1) {
            window.top.postMessage('gotoHome');
          } else {
            this.$router.push(pcUrlName);
          }
        }
      }
    }
  }
};
</script>
<style lang='scss' scoped>
    .wrap {
        width: 400px;
        /* height: 200px; */
        border: 1px solid #c7c4c4;
        border-radius: 7px;
        box-shadow: 0 2px 4px 0 rgba(0, 0, 0, .12), 0 0 6px 0 rgba(0, 0, 0, .04);
        display: flex;
        margin-left: 34%;
        padding-bottom: 10px;
        background-color: #fff;
    }
</style>
